        var unDbStore = new Ext.data.JsonStore({
    		url: '/weihe/getList_unDb',
			root: 'datas',
			fields : [{
			        	   name:'UnDbId',mapping:'id'
			          },{
			        	   name:'UnDbCode',mapping:'code' 
			          },{
			        	   name:'UnDbTaxSum',mapping:'taxSum' 
			          },{
        				   name:'UnDbTab',mapping:'tab'
        			  },{
        				   name:'UnDbReason',mapping:'reason'
        			  },{
        				   name:'UnSubmitDate',mapping:'submitDate',type : 'date', dateFormat:"Y-m-d"
        			  }],
						listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_unDb',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
        
        var dbItemStore = new Ext.data.JsonStore({
			url: '/weihe/getItems_unDb',
			root: 'datas',
			fields : [{
			        	   name:'TaxId',mapping:'id'
			          },{
			        	   name:'TaxName',mapping:'name' 
			          },{
        				   name:'TaxCode',mapping:'code'
        			  },{
        				   name:'TaxNoticeDate', mapping:'noticeDate',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'TaxPromiseDate', mapping:'promiseDate',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'TaxActualDate', mapping:'actualDate',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'TaxMoney',mapping:'money'
        			  },{
        				   name:'TaxTaxRate',mapping:'taxRate'
        			  },{
        				   name:'TaxFlag',mapping:'flag'
        			  },{
        				   name:'TaxTax',mapping:'tax'
        			  },{
        				   name:'TaxReason',mapping:'reason'
        			  },{
        				   name:'TaxSubmitDate', mapping:'submitDate',type : 'date', dateFormat:"Y-m-d"
        			  },{
  						name:'TaxCheckCode',mapping:'unSubmit', convert:function(v){ 
							return v ? v.checkCode : undefined;}
        			  },{
    						name:'TaxCustomCode',mapping:'unSubmit', convert:function(v){ 
							return v ? v.customCode : undefined;}
        			  }],
						listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_unDb',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
       
        
unDbs = function(){
	
	var tmp='';

	
  return{
	  
	  
		listPanel : function(){
	  
		var listPanel = new Ext.Panel( {
			                    region : 'north',
			                    layout : 'border',
			                    frame  : true,
			                    height :250,
			                    items  : [unDbs.listGrid(),unDbs.listForm()] 
		                      });
	  
	  return listPanel;
},

listForm : function(){
    


		var button_add = new Ext.Button({
			text : '添加',
			handler : function() {
				progressConsole();
				if(listForm.form.isValid()){ 
					Ext.getCmp("unDbItemForm").buttons[0].enable();
					Ext.getCmp("unDbItemForm").buttons[1].enable();
					Ext.getCmp("unDbItemForm").buttons[2].enable();
					if (listForm.form.findField("UnDbId").getValue() == "") {
						 listForm.form.submit({
						     url : '/weihe/add_unDb',
						     success : function(form, action) {
							       if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
								        Ext.Msg.alert('消息', action.result.msg, function() {
								        Ext.getCmp("unDbForm").form.reset();
									    Ext.getCmp("unDbItemForm").form.findField('unDb.id').setValue(action.result.unDb_id);
									    Ext.getCmp("unDbGrid").getStore().load({params : {start : action.result.total-1, limit : 5}});
								        });
							       }
						     }
					      });
					}else {
							listForm.form.submit({
								url : '/weihe/update_unDb',
								success : function(form, action) {
									 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
										Ext.Msg.alert('消息', action.result.msg, function() {
											Ext.getCmp("unDbGrid").getStore().load({params : {start : 0, limit : 5}});
										});
									}
							   }
							});
					}
				}else{
					Ext.Msg.alert('提示','请输入相关内容');
				}
			}
		});

	var button_clear = new Ext.Button({
		text : '清空',
		handler : function() {
		
			listForm.form.reset();
			listForm.buttons[0].setText('添加');
			Ext.getCmp("unDbItemForm").form.reset();
			Ext.getCmp("unDbItemForm").buttons[0].disable();
		    Ext.getCmp("unDbItemForm").buttons[1].disable();
		    Ext.getCmp("unDbItemForm").buttons[2].disable();
		    Ext.getCmp("unDbGrid").getStore().removeAll();
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		handler : function() {
			var id = listForm.form.findField('UnDbId').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/delete_unDb',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
							if (json.deny) {
										Ext.Msg.alert('消息', json.msg);
							}else{
								Ext.Msg.alert('消息', json.msg, function() {
									Ext.getCmp("unDbGrid").getStore().load({params : {start : 0, limit : 5}});
									listForm.form.reset();
									listForm.buttons[0].setText('添加');
								});
							}
						}else{
							Ext.Msg.alert('消息', json.msg);
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params: { 'unDb.id' : listForm.form.findField('UnDbId').getValue() }
				});
			}
		}
	});
	  
			var listForm = new Ext.form.FormPanel({
			id : 'unDbForm',
			region : 'east',
			title : '退税信息',
			frame : true,
			width : 310,
			collapseMode :'mini',
			collapsible : true,
			autoScroll : true,
			labelAlign : 'right',
			labelWidth : 70,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
				id: 'UnDbId',
				xtype : 'hidden',
				name : 'unDb.id'
			},{
				id: 'UnDbCode',
				fieldLabel: "接单号",
				name: "unDb.Code"
			},{
				id:'UnDbReason',
				fieldLabel : '未退原因',
 				name : 'unDb.reason'
			}],
			buttons : [button_add,button_clear,button_del]
	});
	  
	  return listForm;
},  
	  
	  
  listGrid : function(){
	  
		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 5,
			store : unDbStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var listGrid = new Ext.grid.GridPanel({
		   id:'unDbGrid',
		   region : 'center',
		   minColumnWidth : 35,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : unDbStore,
		   columns: [
		             {header : '接单号', dataIndex : 'UnDbCode'},
		             {header : '税金', dataIndex : 'UnDbTaxSum'},
		             {header : '未退原因', dataIndex : 'UnDbReason'}
		             ],
         sm : rowSelectionModel,
         listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   		var record = grid.getStore().getAt(rowIndex);
			   		if(record.get('UnDbCode') == '合计'){
			   			 Ext.Msg.alert('提示','不能修改合计项!');
			   		}else{
				   		tmp = record.id;
				   		Ext.getCmp("unDbForm").form.loadRecord(record);
				   		Ext.getCmp("unDbItemForm").form.findField('unDb.id').setValue(record.id);
				   		Ext.getCmp("unDbItemForm").buttons[0].enable();
						Ext.getCmp("unDbItemForm").buttons[1].enable();
						Ext.getCmp("unDbItemForm").buttons[2].enable();
						Ext.getCmp("unDbForm").buttons[0].setText('修改');
						Ext.getCmp("unDbItemGrid").getStore().baseParams = {'unDb.id': record.id};
						Ext.getCmp("unDbItemGrid").getStore().load({params : {start : 0, limit : 5}});
		   		}
			   }
		   },
		  bbar : pageToolBar
});
		return listGrid;
	},
  
    grid : function(){
	 


		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 5,
			store : dbItemStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   


		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var grid = new Ext.grid.GridPanel({
		   id:'unDbItemGrid',
		   title : '货物信息表',
		   region : 'center',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
		   store : dbItemStore,
		   columns: [
		             {header : '提交日期', dataIndex : 'TaxSubmitDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y-m-d')},
		             {header : '核销单号', dataIndex : 'TaxCheckCode'},
		             {header : '报关单号', dataIndex : 'TaxCustomCode'},
		             {header : '开票价', dataIndex : 'TaxMoney'},
		             {header : '通知日期', dataIndex : 'TaxNoticeDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y-m-d')},
		             {header : '货物名称', dataIndex : 'TaxName'},
		             {header : '商品编码', dataIndex : 'TaxCode'},
		             {header : '承诺日期', dataIndex : 'TaxPromiseDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y-m-d')},
		             {header : '实际日期', dataIndex : 'TaxActualDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y-m-d')},
		             {header : '退税率(%)', dataIndex : 'TaxTaxRate'},
		             {header : '退税金额', dataIndex : 'TaxTax'},
		             {header : '未提交原因', dataIndex : 'TaxReason'}
          ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   if(record.get('TaxCheckCode') == '合计'){
			      Ext.Msg.alert('提示','不能修改合计项!');
			   }else{
				   Ext.getCmp("unDbItemForm").form.findField('code').setValue(record.get('TaxCheckCode'));
				   Ext.getCmp("unDbItemForm").form.findField('submitDate').setValue(record.get('TaxSubmitDate'));
				   Ext.getCmp("unDbItemForm").buttons[0].setText('修改');
			   }
		   }
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return grid;
	},
	unDbsForm : function(){
		
		

		var button_add = new Ext.Button({
			text : '查看',
			disabled : true,
			handler : function() {
				if(unDbsForm.form.isValid()){ 	
					if (unDbsForm.form.buttons[0].getText() == "查看") {
							Ext.getCmp("unDbItemGrid").getStore().baseParams = {'flag':'look','code':unDbsForm.form.findField('code').getValue()};
							Ext.getCmp("unDbItemGrid").getStore().load({params : {start : 0, limit : 5}});
							unDbsForm.form.findField('code').readOnly = true;
							unDbsForm.form.buttons[0].setText('添加');
					}else if(unDbsForm.form.buttons[0].getText() == "添加"){
						progressConsole();
						unDbsForm.form.submit({
							  url : '/weihe/addItem_unDb',
							   success : function(form, action) {
								 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										var i = unDbsForm.form.findField('unDb.id').getValue();
										unDbsForm.form.reset();
										 unDbsForm.form.findField('unDb.id').setValue(i);
										 Ext.getCmp("unDbGrid").getStore().reload();
										 Ext.getCmp("unDbItemGrid").getStore().baseParams = null;
										 Ext.getCmp("unDbItemGrid").getStore().baseParams = {'unDb.id': unDbsForm.form.findField('unDb.id').getValue()};
										 Ext.getCmp("unDbItemGrid").getStore().load({params : {start : 0, limit : 5}});
										 unDbsForm.buttons[0].setText('查看');
									});
								  }
							    },
							    failure : function(form, action) {
	      							Ext.Msg.alert('错误', action.result.msg);
	      						}
						    });
					}else if(unDbsForm.form.buttons[0].getText() == "修改"){
						progressConsole();
						unDbsForm.form.submit({
							  url : '/weihe/updateItem_unDb',
							   success : function(form, action) {
								 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										var i = unDbsForm.form.findField('unDb.id').getValue();
										unDbsForm.form.reset();
										 unDbsForm.form.findField('unDb.id').setValue(i);
										 Ext.getCmp("unDbGrid").getStore().reload();
										 Ext.getCmp("unDbItemGrid").getStore().baseParams = null;
										 Ext.getCmp("unDbItemGrid").getStore().baseParams = {'unDb.id': unDbsForm.form.findField('unDb.id').getValue()};
										 Ext.getCmp("unDbItemGrid").getStore().load({params : {start : 0, limit : 5}});
										 unDbsForm.buttons[0].setText('查看');
									});
								  }
							    },
							    failure : function(form, action) {
	      							Ext.Msg.alert('错误', action.result.msg);
	      						}
						    });
					}
				}else{
					Ext.Msg.alert('提示','请输入相关内容');
				}
			}
		
			
		});

	var button_clear = new Ext.Button({
		text : '清空',
		disabled : true,
		handler : function() {
		var i = unDbsForm.form.findField('unDb.id').getValue();
			unDbsForm.form.reset();
			unDbsForm.form.findField('unDb.id').setValue(i);
			 Ext.getCmp("unDbItemGrid").getStore().removeAll();
		    unDbsForm.buttons[0].setText('查看');
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		disabled : true,
		handler : function() {
			var id = unDbsForm.form.findField('code').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				unDbsForm.form.submit({
					  url : '/weihe/deleteItem_unDb',
					   success : function(form, action) {
						 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
							Ext.Msg.alert('消息', action.result.msg, function() {
								var i = unDbsForm.form.findField('unDb.id').getValue();
								unDbsForm.form.reset();
								 unDbsForm.form.findField('unDb.id').setValue(i);
								 Ext.getCmp("unDbGrid").getStore().reload();
								 Ext.getCmp("unDbItemGrid").getStore().baseParams = null;
								 Ext.getCmp("unDbItemGrid").getStore().baseParams = {'unDb.id': unDbsForm.form.findField('unDb.id').getValue()};
								 Ext.getCmp("unDbItemGrid").getStore().load({params : {start : 0, limit : 5}});
								 unDbsForm.buttons[0].setText('查看');
							});
						  }
					    },
					    failure : function(form, action) {
							Ext.Msg.alert('错误', action.result.msg);
						}
				    });
			}
		}
	});
	
		var unDbsForm = new Ext.form.FormPanel({
			id : 'unDbItemForm',
			title : '货物信息',
			frame : true,
			width : 310,
			region : 'east',
			autoScroll : true,
			labelAlign : 'right',
			labelWidth : 70,
			collapseMode :'mini',
			collapsible : true,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
				xtype : 'hidden',
				name : 'unDb.id'
			},{
				id:'TaxCode',
				fieldLabel : '核销单号',
				name : 'code'
			},{ 
				id: 'TaxSubmitDate',
				xtype: 'datefield',
                fieldLabel: "提交日期",
                format : 'Y-m-d',
                name: 'submitDate'
			}],
			buttons : [button_add,button_clear,button_del]
		
	});
		return unDbsForm;
	}
  }
}();








